﻿@using X.PagedList;
@using X.PagedList.Mvc.Core;
@using X.PagedList.Mvc.Common;
@using FwProject.Restaurant.Dto
@model IPagedList<LoadCarDetailsOutputDto>
@{
    Layout = null;
    var count = 0;
    var countproduct = 0;
    var distributioncount = 0;
    var remaining = 0;
    var recoverycount = 0;
    int x = 0;
    var sumLoadCarCount = 0;
    var sumRestaurantInfoCount = 0;
    if (Model.Count > 0)
    {
        if (Model.PageNumber != 1)
        {
            x = (Model.PageNumber - 1) * Model.PageSize;
        }
    }
}
<div id="table_print" style="max-height:600px;overflow-y:scroll;">

    <table class="table table-bordered table-hover table-rowselected" id="t">
        <thead>
            <tr>
                <th style="width:45px">序号</th>
                <th>审核状态</th>
                <th>配送状态</th>
                <th>装车单号</th>
                <th>装车日期</th>
                <th>车牌号</th>
                <th>司机</th>
                <th>总装箱数量</th>
                <th>已配送餐厅数</th>
                <th>货品名称</th>
                <th>装车单位</th>
                <th>装车数量</th>
                <th>已配送数量</th>
                <th>剩余数量</th>
                <th>已回收数量</th>
            </tr>
        </thead>
        <tbody>
            @if (Model.Count == 0)
            {
                <tr><td class="text-center" colspan="15">暂无装车信息</td></tr>
            }
            else
            {
                foreach (var item in Model)
                {
                    x++;
                    count = item.Lodings.Count;
                    if (count > 0)
                    {
                        countproduct = countproduct + item.Lodings.Sum(o => o.Countproduct);
                        distributioncount = distributioncount + item.Lodings.Sum(o => o.Distributioncount);
                        remaining = remaining + item.Lodings.Sum(o => o.Remaining);
                        recoverycount = recoverycount + item.Lodings.Sum(o => o.Recoverycount);
                        for (int i = 0; i < item.Lodings.Count; i++)
                        {
                            <tr>
                                @if (i == 0)
                                {
                                    sumLoadCarCount += item.CountProduct;
                                    sumRestaurantInfoCount += item.RestaurantInfoCount;
                                    <td rowspan="@count">@x</td>
                                    <td rowspan="@count">@Html.Raw(item.ExamineStatus == FwProject.Core.Restaurant.ExamineStatus.已审核 ? $"<span style='color:green'>{item.ExamineStatus.ToString()}</span>" : $"{item.ExamineStatus.ToString()}")</td>
                                    <td rowspan="@count">@item.CarStatus.ToString()</td>
                                    <td rowspan="@count"><a href="javascript:top.window.openTab(1056,'装车单[@item.CreationNumber]','@Url.Action("ExamineLoadingCar",new { id=item.Id})')">@item.CreationNumber</a></td>
                                    <td rowspan="@count">@item.CreationTime.ToString("yyyy-MM-dd HH:mm:ss")</td>
                                    <td rowspan="@count">@item.PlatesNumber</td>
                                    <td rowspan="@count">@item.Name</td>
                                    <td rowspan="@count">@item.CountProduct</td>
                                    <td rowspan="@count">@item.RestaurantInfoCount</td>
                                    <td>@item.Lodings[i].Name</td>
                                    <td>@item.Lodings[i].Unit.ToString()</td>
                                    <td>@item.Lodings[i].Countproduct</td>
                                    <td>@item.Lodings[i].Distributioncount</td>
                                    <td>@item.Lodings[i].Remaining</td>
                                    <td>@item.Lodings[i].Recoverycount</td>
                                }
                                else
                                {
                                    <td>@item.Lodings[i].Name</td>
                                    <td>@item.Lodings[i].Unit.ToString()</td>
                                    <td>@item.Lodings[i].Countproduct</td>
                                    <td>@item.Lodings[i].Distributioncount</td>
                                    <td>@item.Lodings[i].Remaining</td>
                                    <td>@item.Lodings[i].Recoverycount</td>
                                }
                            </tr>
                        }
                    }
                }
                <tr class="footer">
                    <td style="color:red;">合计</td>
                    <td colspan="6"></td>
                    <td>@sumLoadCarCount</td>
                    <td>@sumRestaurantInfoCount</td>
                    <td></td>
                    <td style="color:red;" colspan="2">@countproduct</td>
                    <td style="color:red;">@distributioncount</td>
                    <td style="color:red;">@remaining</td>
                    <td style="color:red;">@recoverycount</td>
                </tr>
            }
        </tbody>
    </table>
</div>
<div class="row pagedinfo">
    <div class="col-sm-5">
        @*共 @Model.TotalItemCount 条，@Model.PageSize 条/页 当前第 @Model.PageNumber/@Model.PageCount 页*@
        共 @Model.TotalItemCount 条，
        <select class="form-control" id="pageSize" style="width:70px;display:initial">
            @for (int z = 10; z < 100; z = z + 10)
            {
                if (z == Model.PageSize)
                {
                    <option selected value="@z">@z</option>
                }
                else
                {
                    <option value="@z">@z</option>
                }
            }
        </select> &nbsp;条/页 当前第 @Model.PageNumber/@Model.PageCount 页
    </div>
    <div class="col-sm-7">
        <input type="hidden" id="pageurl" value="&ExamineStatus=@(Context.Request.Query["ExamineStatus"])&DriverId=@(Context.Request.Query["DriverId"])&PlatesNumber=@(Context.Request.Query["PlatesNumber"])&BeginLimit=@(Context.Request.Query["BeginLimit"])&EndLimit=@(Context.Request.Query["EndLimit"])" />
        @Html.PagedListPager(Model, page => Url.Action("LoadingDetails", new { id = page,size= Context.Request.Query["size"], ExamineStatus = Context.Request.Query["ExamineStatus"], DriverId = Context.Request.Query["DriverId"], PlatesNumber = Context.Request.Query["PlatesNumber"], BeginLimit = Context.Request.Query["BeginLimit"], EndLimit = Context.Request.Query["EndLimit"] }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions() { AllowCache = false, HttpMethod = "Get", UpdateTargetId = "data_list", OnSuccess = "AjaxSuccessCallback", OnBegin = "AjaxBegin" }))
    </div>
</div>
